import { IStorageUtils } from "../app_base/module/utils/StorageUtils";
import { app } from "../base";

/**
 * cocos下的本地持久化实现类
 */
export class CocosStorageUtils implements IStorageUtils {
    removeValue(key: string): void {
        if (!CC_PREVIEW) {
            key = app.md5(key);
        }
        cc.sys.localStorage.removeItem(key);
    }

    setValue(key: string, value: string | number | boolean): void {
        if (!CC_PREVIEW) {
            key = app.md5(key);
        }
        cc.sys.localStorage.setItem(key, value);
    }

    getValue<T>(key: string): T {
        if (!CC_PREVIEW) {
            key = app.md5(key);
        }
        return cc.sys.localStorage.getItem(key);
    }

    clear(): void {
        cc.sys.localStorage.clear();
    }
}